﻿#ifndef WIDGETGRAPHICSVIEW_H
#define WIDGETGRAPHICSVIEW_H

#include "Graphics/graphicsview.h"

#include <QWidget>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QMap>
#include <mutex>

typedef struct
{
    int index;
    QString path;
    int width;
    int height;
    int rotate;
    int centerx;
    int centery;
    bool matched;
} SourceItemInfo;

class PictureRectItem;
class QLabel;
class WidgetGraphicsView : public QWidget
{
    Q_OBJECT
public:
    enum class EnumDragMode { Mode_Select = 0, Mode_Drag };
    explicit WidgetGraphicsView(QWidget *parent = nullptr);

private:
    void init();

public:
    void switchInteractiveMode(EnumDragMode mode);

    void switchSelectedItemVisiblity();

private slots:
    void slot_add_new_picture(const QString &path, int index);

    void slot_wheel_graphics_view(float value);

    void slot_save_current_visible_scene();

    void slot_add_new_graphics_item(int index, PictureRectItem *item);

    void slot_btn_reset_view_click();

    void slot_btn_close_select_click();

    void slot_btn_restore_view_click();

    void slot_btn_save_view_click();

    void slot_del_all_graphics_item();

    void slot_close_slected_graphics_item();

private:
    // 主视图
    GraphicsView mGraphicsView;

    // 主场景
    QGraphicsScene mGraphicsScene;

    // 计算图片个数
    uint32_t mTotalPictureNumber = 0;

    // 缩放指数
    int32_t mScaleValue = 120;

    // 图片列表
    QMap<int, SourceItemInfo> mMapSourceInfo;

    // 列表同步锁
    std::mutex mMapMutex;

    // 保存进度展示
    QLabel *mSaveProcess = nullptr;
};

#endif // WIDGETGRAPHICSVIEW_H
